// fs_wmall/pages/sjzx/sjzx/permoney.js
import {
	formatTime
} from '../../../utils/util'
var base = require('../../../utils/lang.js');
const _ = base._

var app = getApp();
const _time = formatTime({
	date: new Date(),
	type: 'yyyy-mm-dd',
	symbol: '-'
})

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		_t: base._t(),
		balance: '0',
		date_start: '2021-01-01',
		date_end: _time,
		list: [],
		page: 1,
		pageSize: 20,
		store_id: null
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		const isWei = base.isWeiFn()
		this.setData({
			isWei
		})
		const {
			store_id
		} = options
		this.setData({
			store_id
		})
		app.setNavigationBarColor(this);
		this.getList()
	},

	getList() {
		wx.showLoading({
			title: _('数据加载中...'),
			mask: true,
		});
		let {
			page,
			pageSize,
			store_id,
			list,
			date_start,
			date_end
		} = this.data
		const start = parseInt(+new Date(date_start) / 1000)
		const end = parseInt(+new Date(date_end) / 1000)

		app.util.request({
			'url': 'entry/wxapp/DepositList',
			'cachetime': '0',
			data: {
				store_id,
				page,
				pagesize: pageSize,
				start,
				end
			},
			success: res => {
				console.log('zcjpp')
				console.log(res)

				const _balance = res.data.info && res.data.info.sy_deposit
				this.setData({
					balance: _balance
				})

				if (!res.data.list.length) {
					wx.showToast({
						title: _('没有更多数据了'),
						icon: 'none',
						duration: 1500,
					});
					return
				}
				const _list = list.concat(res.data.list)
				this.setData({
					list: _list
				})
			},
		})
	},

	bindPickerChangeStart: function(e) {
		this.setData({
			date_start: e.detail.value,
		})
	},

	bindPickerChangeEnd: function(e) {
		this.setData({
			date_end: e.detail.value,
		})
	},

	chooseTimeBtnFn() {
		this.setData({
			list: [],
			page: 1,
		})
		this.getList()
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		this.setData({
			_t: base._t()
		})
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
		let {
			page
		} = this.data
		this.setData({
			page: page + 1
		})
		this.getList()
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
